package cn.edu.zafu.bigdata.lyq.work6;
public class ThrowsArithmeticException {

    // 定义方法 divide，计算两个整数的除法结果
    public static double divide(int a, int b) throws ArithmeticException {
        if (b == 0) {
            throw new ArithmeticException("除数不能为0");
        }
        return (double) a / b;
    }

    public static void main(String[] args) {
        int x = 10;
        int y = 0;
        try {
            double z = divide(x, y);
            System.out.println("结果是: " + z);
        } catch (ArithmeticException e) {

            System.err.println("错误: " + e.getMessage());
        }
    }
}